<?
require_once 'config.php';
   $HomePage = false;
   $productsPage = true;
   $templateDetail = new TemplateDetail;
   $pro_id = getValue("pro_id","int","GET",0);
   if($pro_id <= 0){
      redirect('/trang-chu.html');
   }
   $product_info = $templateDetail->product_info($pro_id);
   if($product_info == NULL) redirect('/trang-chu.html');

//Xử lý link
$partnerId = preg_replace('/.+\?partnerId=/','',$_SERVER['REQUEST_URI']);
//nếu link thường(không có partnerId)
if (strlen(strstr($partnerId, 'phan-mem')) > 0) {
    //Kiểm tra tiếp xem có tồn tại partnerId ko ?
    if(isset($_COOKIE['partnerId']) && $_COOKIE['partnerId'] != 0) {
        $partnerId = $_COOKIE['partnerId'];
    }else {
        $partnerId = 0;   
    }
}
//Ngược lại nếu link có id
else {
    $db_this_partner = new db_query('SELECT use_id,use_partners FROM users WHERE use_id = '.$partnerId);
    $this_partner = mysql_fetch_assoc($db_this_partner->result);
    if($this_partner['use_partners'] == 1) {
        //setcookie cho partner trong 5 ngày
        setcookie("partnerId",$partnerId,time() + 3600*120);
    }else {
        $partnerId = 0;
        setcookie("partnerId",0,time() + 3600*120);
    }
}

$fs_errorMsg = '';
$bg_mess = '';

$action			= getValue("action","str","POST","");
if($action 		== 'execute'){
    
    $reg_date		=	time();
    $reg_active = 0;
    
    $myform	=	new generate_form();
    $myform->removeHTML(0);
    
    $myform->add('reg_name', 'reg_name', 0, 0, '', 1, 'bạn chưa nhập tên', 0);
    $myform->add('reg_phone', 'reg_phone', 0, 0, '', 1, 'bạn chưa nhập điện thoại', 0);
    $myform->add('reg_email', 'reg_email', 0, 0, '', 1, 'bạn chưa nhập email', 0);
    $myform->add('reg_region','reg_region', 1, 0, '', 0, '', 0, '');
    $myform->add('reg_product_id','reg_product_id', 1, 0, '', 0, '', 0, '');
    $myform->add('reg_term','reg_term', 1, 0, '', 0, '', 0, '');
    $myform->add('reg_date','reg_date', 1, 1, '', 0, '', 0, '');
    $myform->add('reg_user_id','reg_user_id', 1, 0, '', 0, '', 0, '');
    $myform->add("reg_active","reg_active", 1, 1, 0, 0,"",0,""); 
	$myform->addTable('register');
    
	//Check form data
	$fs_errorMsg .= $myform->checkdata();
	if($fs_errorMsg == ""){
		$db_insert 		= new db_execute_return();
		$last_id			= $db_insert->db_execute($myform->generate_insert_SQL());
        if($last_id > 0) {
            $bg_mess = 'Đăng ký thành công. Chúng tôi sẽ liên hệ với bạn sớm nhất có thể. Xin cám ơn !';
            echo '<script>alert("Đăng ký thành công. Chúng tôi sẽ liên hệ với bạn sớm nhất có thể. Xin cám ơn !")</script>';
            echo '<script>window.location.href = "/"; </script>';
        }
	}
}
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="vi" lang="vi" xmlns:og="http://ogp.me/ns#" xmlns:fb="https://www.facebook.com/2008/fbml">
<head>
<link href="<?=DOMAIN?>/favicon.png" type="image/x-icon" rel="shortcut icon"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="AUTHOR" content="MassSeo" />
<meta name="COPYRIGHT" content="Copyright (C) 2012 MassSeo.vn" />
<meta name="ROBOTS" content="INDEX, FOLLOW" />
<meta name="RATING" content="GENERAL" />
<?=showSeoMeta('products',$pro_id)?>
<link rel="canonical" href="<?=DOMAIN.generate_product_detail_url($product_info)?>" />
<?/*    Facebook content    */ ?>
<meta property="og:title" content="<?=$product_info['pro_name']?>" />
<meta property="og:type" content="article" />
<meta property="og:url" content="<?=DOMAIN.generate_product_detail_url($product_info)?>" />
<meta property="og:image" content="<?=DOMAIN.PATH_PICTURE_PRODUCT.$product_info['pro_image']?>" />
<meta property="og:site_name" content="MassSeo" />
<meta property="og:description" content="<?=$product_info['pro_description']?>" />
<meta property="fb:admins" content="<?=FACEBOOK_ADMIN?>" />
<meta property="fb:app_id" content="<?=FACEBOOK_APP?>"/>

<link rel="stylesheet" type="text/css" href="../themes/css/base.css"/>
<link rel="stylesheet" type="text/css" href="../themes/css/detail.css"/>

<script type="text/javascript" src="../themes/js/jquery.js"></script>
<script type="text/javascript" src="<?=TEMPLATE_PATH?>js/detail.js"></script>
    <?=$analytics?>

</head>
<body>
<? require_once("../social_plugins/facebook.php");?>
   <div class="globalContainer">
      <?
         include('view/common/vic_header.php');
      ?>
      <div class="line"></div>
      <div class="content">
         <div class="nav_wrap">
            <div class="nav_inner w1130">
            <div class="nav_soft_name" title="<?=$product_info['pro_name']?>">
               <p class="soft_name"><?=$product_info['pro_name']?></p>
               <div class="product_menu">
                  <div class="f_product">
                     <?
                        foreach($products as $row){
                     ?>
                        <div class="product_once">
                           <a href="<?=generate_product_detail_url($row)?>"><img src="<?=PATH_PICTURE_PRODUCT.$row['pro_image_tiny']?>"/></a>
                           <div class="product_description">
                              <a href="<?=generate_product_detail_url($row)?>"><p class="product_name" title="<?=$row['pro_name']?>"><?=$row['pro_name']?></p></a>
                              <p class="product_summary" title="<?=$row['pro_title']?>"><?=$row['pro_title']?></p>
                           </div>
                        </div>
                        <p class="p_line"></p>
                     <?
                        }
                     ?>
                     <a href="/phan-mem/" class="view_all"><span class="view_all_text">Xem tất cả </span><span class="arrow"></span></a>
                  </div>
               </div>
            </div>
               <ul class="nav">
                  <li class="nav_introduction nav_active_default"><a href="#introduction">Giới thiệu</a></li>
                  <li class="nav_features"><a href="#feature">Tính Năng</a></li>
                  <li class="nav_benefits"><a href="#benefits">Lợi ích</a></li>
                  <li class="nav_guide"><a href="#guide">Hướng dẫn</a></li>
                  <li class="nav_customers"><a href="#customers">Khách hàng</a></li>
                  <li style="display: none;"><a href="#feel"></a></li>
               </ul>
               <div class="try_down_buy">
                  <p class="try">DÙNG THỬ MIỄN PHÍ</p>
                  <p class="down_buy"><a href="<?=$product_info['pro_download_link']?>" target="_blank">DOWNLOAD</a> | <a href="javascript:;" class="buy">MUA</a></p>
               </div>
            </div>
         </div>
         <div class="soft_introduction_wrap" >
            <div class="soft_introduction w1130" id="introduction">
               <img src="<?=PATH_PICTURE_PRODUCT.$product_info['pro_image_detail']?>" alt="<?=$product_info['pro_name']?>"/>
               <div class="soft_inf">
                  <h1 class="soft_name1"><?=$product_info['pro_name']?></h1>
                  <h2 class="soft_tit"><?=$product_info['pro_title']?></h2>
                  <p class="soft_des"><?=$product_info['pro_description']?></p>
                  <div class="social_wrap">
                        <ul>
                            <li><div class="fb-like" data-href="<?=DOMAIN.$_SERVER['REQUEST_URI']?>" data-width="450" data-layout="button_count" data-show-faces="false" data-send="false"></div></li>
                            <li><a href="https://twitter.com/share" class="twitter-share-button" data-url="<?=DOMAIN.$_SERVER['REQUEST_URI']?>">Tweet</a></li>
                            <li><div class="g-plusone" data-size="medium" data-annotation="inline" data-width="300" data-href="<?=DOMAIN.$_SERVER['REQUEST_URI']?>"></div></li>
                        </ul>
                        
                        <script>
                            !function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');
                        </script>
                        <script type="text/javascript" src="https://apis.google.com/js/plusone.js">
                          {lang: 'vi'}
                        </script>
                        
                    </div>
               </div>
               <div class="soft_more_inf">
                  <p class="down_buy_big"><a href="<?=$product_info['pro_download_link']?>" target="_blank">DOWNLOAD</a> | <a href="javascript:;" class="buy">MUA</a></p>
                  <p class="soft_price">
                     <?if($product_info['pro_price_year'] == 0){?>
                        <?=format_price_fontend(($product_info['pro_promotion'] == 1) ? $product_info['pro_price_lifetime_promotion'] : $product_info['pro_price_lifetime'])?> VNĐ / Trọn đời</p>
                     <?}else{?>
                           <?=format_price_fontend(($product_info['pro_promotion'] == 1) ? $product_info['pro_price_year_promotion'] : $product_info['pro_price_year'])?> VNĐ / NĂM</p>                     
                           <p class="soft_price"><?=format_price_fontend(($product_info['pro_promotion'] == 1) ? $product_info['pro_price_lifetime_promotion'] : $product_info['pro_price_lifetime'])?> VNĐ / TRỌN ĐỜI</p>
                  <?}?>
                  <p class="try_big">DÙNG THỬ MIỄN PHÍ</p>
                  <ul>
                  <li class="inf_one">Giao diện đơn giản, tiện dụng</li>
                  <li class="inf_one">Triển khai nhanh chóng</li>
                  <li class="inf_one">Hiệu quả mang lại cao</li>
                  <li class="inf_one">Bảo hành, nâng cấp liên tục</li>
                  <li class="inf_one">Hỗ trợ nhanh, trọn đời miễn phí</li>
                  </ul>
               </div>
            </div>
         </div>
         <div class="line1"></div>
         <div class="soft_feature_wrap" >
            <div class="feature w1130" id="feature">
               <p class="features_title">Tính năng</p>
               <div class="_content">
                  <?=$product_info['pro_features']?>
               </div>
            </div>
         </div>
         <div class="line1"></div>
         <div class="soft_benefits_wrap" >
            <div class="benefits w1130" id="benefits">
               <p class="features_title">Lợi ích</p>
               <div class="_content">
                  <?=$product_info['pro_benefits']?>
               </div>
            </div>
         </div>
         <div class="line1"></div>
         <div class="soft_guide_wrap" >
            <div class="guide w1130" id="guide">
               <p class="features_title">Hướng dẫn</p>
               <div class="_content">
                  <?=$product_info['pro_guide']?>
               </div>
            </div>
         </div>
         <div class="line1"></div>
         <div class="soft_customers_wrap" >            
            <div class="customers w1130" id="customers">
               <p class="features_title">Khách hàng</p>
               <div class="_content">
                  <?=$product_info['pro_customers']?>
               </div>
            </div>
         </div>
         <div class="line1"></div>
         <div class="soft_feel_wrap" >            
            <div class="feel w1130" id="feel">
               <div class="_content">
                  <?=$product_info['pro_feel']?>
               </div>
            </div>
         </div>
         <div class="line1"></div>
         <div class="product_register_wrap" id="product_register_wrap">
            <div class="product_register w1130">
                <h3>Đăng ký mua</h3>
                <form action="<?=$_SERVER['REQUEST_URI']?>" method="POST">
                <?
                if($partnerId != 0) {
                    $db_partner = new db_query('SELECT use_id,use_firstname,use_lastname,use_phone FROM users WHERE use_id = '.$partnerId);
                    $partner = mysql_fetch_assoc($db_partner->result);
                    ?>
                    <div class="product_register_group">
                        <h4 class="partner_off">Phụ trách kinh doanh :  <b style="color: #ff0000;"><?=$partner['use_firstname'].' '.$partner['use_lastname']?> - <?=$partner['use_phone']?></b></h4>
                    </div>
                    <?
                }else {
                    ?>
                    <div class="product_register_group">
                        <h4 class="partner_off">Phụ trách kinh doanh : 0969.925.246 (Mr.Công)</h4>
                    </div>
                    <?
                }
                ?>
                    <div class="product_register_group">
                        <div class="item_left">
                            <h4>Tên của bạn:</h4>
                        </div>
                        <div class="item_right">
                            <input type="text" name="reg_name" />
                        </div>
                    </div>
                    <div class="product_register_group">
                        <div class="item_left">
                            <h4>Số điện thoại:</h4>
                        </div>
                        <div class="item_right">
                            <input type="text" name="reg_phone" />
                        </div>
                    </div>
                    <div class="product_register_group">
                        <div class="item_left">
                            <h4>Emai:</h4>
                        </div>
                        <div class="item_right">
                            <input type="text" name="reg_email" />
                        </div>
                    </div>
                    <div class="product_register_group">
                        <div class="item_left">
                            <h4>Địa chỉ:</h4>
                        </div>
                        <div class="item_right">
                            <div class="reg_region">
                                <input type="radio" name="reg_region" value="1" checked="checked" />
                                <span>Miền Bắc</span>
                            </div>
                            <div class="reg_region">
                                <input type="radio" name="reg_region" value="2" />
                                <span>Miền Trung</span>
                            </div>
                            <div class="reg_region">
                                <input type="radio" name="reg_region" value="3" />
                                <span>Miền Nam</span>
                            </div>
                        </div>
                    </div>
                    <div class="product_register_group">
                        <div class="item_left">
                            <h4>Mua phần mềm:</h4>
                        </div>
                        <div class="item_right">
                            <div class="reg_product_id_wrap">
                                <select name="reg_product_id" class="reg_product_id">
                                <?
                                $db_pro_list = new db_query('SELECT pro_name,pro_id FROM products WHERE 1 LIMIT 10');
                                $pro_list = $db_pro_list->resultArray();unset($db_pro_list);
                                foreach($pro_list as $pro) {
                                    ?>
                                    <option value="<?=$pro['pro_id']?>" <?=$pro['pro_id'] == $pro_id ? 'selected="selected"' : '' ?> ><?=$pro['pro_name']?></option>
                                    <?
                                }
                                ?>
                                </select>
                            </div>
                            <div class="reg_term_wrap">
                                <select name="reg_term" class="reg_term">
                                    <option value="1">1 năm</option>
                                    <option value="3">Vĩnh viễn</option>
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="product_register_group">
                        <div class="item_left">
                            <h4>Giá:</h4>
                        </div>
                        <div class="item_right">
                            <h4 class="price"><span class="price_value"><?=format_price_fontend(($product_info['pro_promotion'] == 1) ? $product_info['pro_price_year_promotion'] : $product_info['pro_price_year'])?></span><span class="price_value_op"> VNĐ</span> <a href="#">(Tham khảo bản giá chi tiết)</a></h4>
                        </div>
                    </div>
                    <div class="product_register_group">
                        <input type="hidden" name="reg_user_id" value="<?=$partnerId?>" />
                        <input type="hidden" name="action" value="execute" />
                        <input class="reg_submit" type="submit" value="Đăng ký mua" />
                    </div>
                    <script>
                        $('.reg_term').change(function() {
                            var term_val = $(this).val();
                            if(term_val == 1) {
                                $('.price_value').html('<?=format_price_fontend(($product_info['pro_promotion'] == 1) ? $product_info['pro_price_year_promotion'] : $product_info['pro_price_year'])?>');
                            }else if(term_val == 3) {
                                $('.price_value').html('<?=format_price_fontend(($product_info['pro_promotion'] == 1) ? $product_info['pro_price_lifetime_promotion'] : $product_info['pro_price_lifetime'])?>');
                            }else {
                                $('.price_value').html('1.000.000 VNĐ');
                            }
                        })
                    </script>
                </form>
            </div>
            <div class="product_register_sub w1130">
                <p>Ngay sau khi bạn đăng ký mua, chúng tôi sẽ liên hệ với bạn để hướng dẫn thanh toán, cài đặt và sử dụng phần mền.</p>
            </div>
            </div>
            <div class="comments_wrap">
                <div class="w1130" style="margin: 0px auto;">
                    <div class="comments">
                        <div class="comments_tab">
                            <div class="comments_tab_item comments_tab_fb active">Facebook</div>
                            <div class="comments_tab_item comments_tab_gg">Google</div>
                        </div>
                        <div class="comments_main">
                            <div class="comments_main_item comments_main_fb" style="z-index: 1000;position: relative">
                                <div class="fb-comments" data-href="<?=DOMAIN.$_SERVER['REQUEST_URI']?>" data-colorscheme="light" data-numposts="5" data-width="950"></div>
                            </div>
                            <div class="comments_main_item comments_main_gg">
                                <div class="g-comments"
                                    data-href="<?=DOMAIN.$_SERVER['REQUEST_URI']?>"
                                    data-width="950"
                                    data-first_party_property="BLOGGER"
                                    data-view_type="FILTERED_POSTMOD">
                                </div>
                            </div>
                        </div>
                    <script>
                        $('.comments_tab_fb').live('click',function(){
                            $('.comments_tab div').removeClass('active');
                            $(this).addClass('active');
                            $('.comments_main_gg').css({'z-index':'100','position':'absolute'});
                            $('.comments_main_fb').css({'z-index':'1000','position':'relative'});
                        }); 
                        $('.comments_tab_gg').live('click',function(){
                            $('.comments_tab div').removeClass('active');
                            $(this).addClass('active');
                            $('.comments_main_fb').css({'z-index':'100','position':'absolute'});
                            $('.comments_main_gg').css({'z-index':'1000','position':'relative'});
                        }); 
                        $('.reg_submit').live('click',function(){
                            if($('input:text[name=reg_name]').val() == '') {
                                alert('Bạn chưa nhập tên');
                                return false;
                            }
                            if($('input:text[name=reg_phone]').val() == '') {
                                alert('Bạn chưa nhập số điện thoại');
                                return false;
                            }
                            if($('input:text[name=reg_email]').val() == '') {
                                alert('Bạn chưa nhập địa chỉ email');
                                return false;
                            }
                        });
                    </script>
                    </div>
                </div>
            </div>
         </div>
         <div class="line"></div>
      <?
         include('view/common/vic_footer.php');
      ?>
   </div>
</body>
</html>